package thread;

/**
 * @author HuangJin
 * @version 1.0
 * describe:使用匿名内部类来完成良好总方式的线程创建
 * @date 2023/3/14 10:44
 */
public class ThreadDemo3 {
    public static void main(String[] args) {
        //第一种继承Thread重写run方法
       Thread t1 = new Thread(){
           @Override
           public void run() {
               for (int i = 0; i <100;i++ ) {
                   System.out.println("抄家的，快开门!");
                }
           }
       };
        //第二种：单独定义线程任务
        /*Runnable r2 = ()-> {
                for (int i = 0; i < 1000; i++) {
                    System.out.println("我是好人，你是谁？");
                }
        };
        Thread t2 = new Thread(r2);

         */
        Thread t2 = new Thread(()-> {
            for (int i = 0; i < 1000; i++) {
                System.out.println("我是好人，你是谁？");
            }
        });
        t1.start();
        t2.start();
    }

}
